//index.js
//获取应用实例
const app = getApp()
var mqtt = require('../../utils/mqtt.js');

Page({
  data: {
    topic:"ZUCC-HJX/rgb",
    R:"",
    G:"",
    B:"",
    rgb: 'rgb(255,0,255)',//初始值
    pick: false
  },
  // 显示取色器
  toPick: function () { 
    this.setData({
      pick: true
    })
  },
  //取色结果回调
  pickColor(e) {
    let rgb = e.detail.color;
    let rgb1 = rgb.split(',');
    let R = parseInt(rgb1[0].split('(')[1]);
    let G = parseInt(rgb1[1]);
    let B = parseInt(rgb1[2].split(')')[0]);

    console.log(R,G,B)
    this.setData({ 
      rgb:rgb, 
      R:R,
      G:G,
      B:B,
   
    })
  },
  //事件处理函数
  TopicInput:function(e){
    
    this.setData({
      topic:e.detail.value
    })
  },

  r_vlaue_Input:function(e){
   
    this.setData({
      R:e.detail.value
    })
  },
  g_vlaue_Input:function(e){
   
    this.setData({
      G:e.detail.value
    })
  },
  b_vlaue_Input:function(e){
   
    this.setData({
      B:e.detail.value
    }) 
  }, 

  //发送mqtt
  sendmqtt: function() {
   
    app.globalData.client.publish(this.data.topic, '{"R":'+this.data.R+',"G":'+this.data.G+',"B":'+this.data.B+'}' );
    console.log("发送成功！");
    
    
  },
  
  

  
})
